<?php 
header("Content-Type: text/x-vCalendar");
header("Content-Disposition: inline; filename=RedJeZaterdag.vcs");

require_once 'common/common.inc.php';

$reservation_id = isset($_REQUEST["reservation_id"]) ? $_REQUEST["reservation_id"] : "";

if ($reservation_id != null && $reservation_id != "") {

  conn();
  $sql = "";
  $sql .= "SELECT ID, START, END, SCHEDULE_ID, SIGN_IN_EMAIL, CAST(CONFIRMED AS unsigned int) CONFIRMED ";
  $sql .= "FROM RESERVATIONS ";
  $sql .= "WHERE ID = '$reservation_id'";
  
  //echo $sql;
  $result = mysql_query($sql);
  if (!$result) {die('Could not exec query: ' . mysql_error());}
  $row = mysql_fetch_array($result, MYSQL_ASSOC);
  $start = strtotime( $row["START"] );
  $end = strtotime( $row["END"] );

  $reservation_startdate = new DateTimeDutch("@".$start, $timezone);
  $reservation_startdate->setTimezone($timezone); 
  $startdate_str = $reservation_startdate->format('Ymd\THis');
  //echo $startdate_str;
  
  $reservation_enddate = new DateTimeDutch("@".$end, $timezone);
  $reservation_enddate->setTimezone($timezone); 
  $enddate_str = $reservation_enddate->format('Ymd\THis');
  close();

  //for timezone issues
  //http://www.pcreview.co.uk/forums/importing-vcs-file-gives-wrong-times-t1809060.html
}
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//RedJeZaterdag Agenda//NONSGML v1.0//EN
BEGIN:VEVENT
DTSTART:<?php echo $startdate_str . "\n"; ?>
DTEND:<?php echo $enddate_str . "\n"; ?>
SUMMARY:Reservering auto wassen (Red Je Zaterdag)
LOCATION:Op de zaak
END:VEVENT
END:VCALENDAR
